llamamos a las librerias

library(sf)
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(mapview)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
##      (status 2 uses the sf package in place of rgdal)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

llamamos la información del entorno … se carga como valor

baseurl <- "http://vport.herrera.unt.edu.ar:8894/geoserver/wfs?"
wfs_request <- "request=GetFeature&service=WFS&version=2.0.0&typeName=espacio01:tuc_juris&outputFormat=application/json"

fi_regions_wfs <- paste0(baseurl,wfs_request)

creamos una tabla a partir de esos valores…

(data frame y sf , xq contiene a demas datos espaciales)

fi_regions <- st_read(fi_regions_wfs)
## Reading layer `OGRGeoJSON' from data source 
##   `http://vport.herrera.unt.edu.ar:8894/geoserver/wfs?request=GetFeature&service=WFS&version=2.0.0&typeName=espacio01:tuc_juris&outputFormat=application/json' 
##   using driver `GeoJSON'
## Simple feature collection with 121 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -66.17672 ymin: -28.02735 xmax: -64.48182 ymax: -26.05595
## Geodetic CRS:  WGS 84

revisamos la estructura del archivo … para encontrar la columna que queremos considerar

su estructura

str(fi_regions)
## Classes 'sf' and 'data.frame':   121 obs. of  5 variables:
##  $ id      : chr  "40" "41" "75" "79" ...
##  $ juris   : chr  "SAN ANDRES" "LOS BULACIOS Y LOS VILLAGRA" "MUN. LULES" "SAN FELIPE Y SANTA BARBARA" ...
##  $ depto   : chr  "CRUZ ALTA" "CRUZ ALTA" "LULES" "LULES" ...
##  $ codigo  : chr  "8154" "" "0077" "8364" ...
##  $ geometry:sfc_MULTIPOLYGON of length 121; first list element: List of 1
##   ..$ :List of 1
##   .. ..$ : num [1:855, 1:2] -65.2 -65.2 -65.2 -65.2 -65.2 ...
##   ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
##  - attr(*, "sf_column")= chr "geometry"
##  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA
##   ..- attr(*, "names")= chr [1:4] "id" "juris" "depto" "codigo"

la columna que nos interesa

sort(unique(fi_regions$juris))
##   [1] ""                                    
##   [2] "7 DE ABRIL"                          
##   [3] "ACHERAL"                             
##   [4] "AGUA DULCE Y LA SOLEDAD"             
##   [5] "ALPACHIRI Y EL MOLINO"               
##   [6] "ALTO VERDE Y LOS GUCHEA"             
##   [7] "AMAICHA DEL VALLE"                   
##   [8] "AMBERES"                             
##   [9] "ANCAJULI"                            
##  [10] "ARCADIA"                             
##  [11] "ATAHONA"                             
##  [12] "BENJAMIN ARAOZ Y EL TAJAMAR"         
##  [13] "BUENA VISTA"                         
##  [14] "CAPITAN CACERES"                     
##  [15] "CEVIL REDONDO"                       
##  [16] "CHOROMORO"                           
##  [17] "CIUDACITA"                           
##  [18] "COLALAO DEL VALLE"                   
##  [19] "COLOMBRES"                           
##  [20] "DELFIN GALLO"                        
##  [21] "EL BRACHO Y EL CEBILAR"              
##  [22] "EL CADILLAL"                         
##  [23] "EL CERCADO"                          
##  [24] "EL CHAÑAR"                           
##  [25] "EL MANANTIAL"                        
##  [26] "EL MOJON"                            
##  [27] "EL MOLLAR"                           
##  [28] "EL NARANJITO"                        
##  [29] "EL NARANJO Y EL SUNCHAL"             
##  [30] "EL POLEAR"                           
##  [31] "EL PUESTITO"                         
##  [32] "EL SACRIFICIO"                       
##  [33] "EL TIMBO"                            
##  [34] "ESCABA"                              
##  [35] "ESQUINA Y MANCOPA"                   
##  [36] "ESTACION ARAOZ Y TACANAS"            
##  [37] "GARMENDIA"                           
##  [38] "GASTONA Y BELICHA"                   
##  [39] "GDOR. PIEDRABUENA"                   
##  [40] "HUASA PAMPA"                         
##  [41] "LA ESPERANZA"                        
##  [42] "LA FLORIDA Y LUISIANA"               
##  [43] "LA RAMADA Y LA CRUZ"                 
##  [44] "LA TRINIDAD"                         
##  [45] "LAS CEJAS"                           
##  [46] "LAS TALAS"                           
##  [47] "LEON ROUGES Y SANTA ROSA"            
##  [48] "LOS BULACIOS Y LOS VILLAGRA"         
##  [49] "LOS GOMEZ"                           
##  [50] "LOS NOGALES"                         
##  [51] "LOS PEREYRAS"                        
##  [52] "LOS PEREZ"                           
##  [53] "LOS PUESTOS"                         
##  [54] "LOS RALOS"                           
##  [55] "LOS SARMIENTO Y LA TIPA"             
##  [56] "LOS SOSA"                            
##  [57] "MANUEL GARCIA FERNANDEZ"             
##  [58] "MANUELA PEDRAZA"                     
##  [59] "MEDINA"                              
##  [60] "MONTE BELLO"                         
##  [61] "MONTEAGUDO"                          
##  [62] "MUN.  JUAN BAUTISTA ALBERDI"         
##  [63] "MUN.  LA COCHA"                      
##  [64] "MUN.  TAFI VIEJO"                    
##  [65] "MUN.  TRANCAS"                       
##  [66] "MUN.  YERBA BUENA"                   
##  [67] "MUN. DE AGUILARES"                   
##  [68] "MUN. DE ALDERETES"                   
##  [69] "MUN. DE BANDA DEL RIO"               
##  [70] "MUN. DE BELLA VISTA"                 
##  [71] "MUN. DE BURRUYACU"                   
##  [72] "MUN. DE CONCEPCION"                  
##  [73] "MUN. DE FAMAILLA"                    
##  [74] "MUN. DE GRANEROS"                    
##  [75] "MUN. DE LAMADRID"                    
##  [76] "MUN. DE MONTEROS"                    
##  [77] "MUN. DE SAN MIGUEL DE TUCUMAN"       
##  [78] "MUN. DE SIMOCA"                      
##  [79] "MUN. LAS TALITAS"                    
##  [80] "MUN. LULES"                          
##  [81] "MUN. TAFI DEL VALLE"                 
##  [82] "PAMPA MAYO"                          
##  [83] "QUILMES Y LOS SUELDOS"               
##  [84] "RACO"                                
##  [85] "RANCHILLOS Y SAN MIGUEL"             
##  [86] "RIO CHICO Y NUEVA TRINIDAD"          
##  [87] "RIO COLORADO"                        
##  [88] "RIO SECO"                            
##  [89] "RUMIPUNCO"                           
##  [90] "SAN ANDRES"                          
##  [91] "SAN FELIPE Y SANTA BARBARA"          
##  [92] "SAN IGNACIO"                         
##  [93] "SAN JAVIER"                          
##  [94] "SAN JOSE DE LA COCHA"                
##  [95] "SAN PABLO Y VILLA NOUGUES"           
##  [96] "SAN PEDRO DE COLALAO"                
##  [97] "SAN PEDRO Y SAN ANTONIO"             
##  [98] "SANTA ANA"                           
##  [99] "SANTA CRUZ Y LA TUNA"                
## [100] "SANTA LUCIA"                         
## [101] "SANTA ROSA DE LEALES Y LAGUNA BLANCA"
## [102] "SARGENTO MOYA"                       
## [103] "SOLDADO MALDONADO"                   
## [104] "TACO RALO"                           
## [105] "TAPIA"                               
## [106] "TENIENTE BERDINA"                    
## [107] "VILLA BELGRANO"                      
## [108] "VILLA DE CHICLIGASTA"                
## [109] "VILLA DE LEALES"                     
## [110] "VILLA PADRE MONTI"                   
## [111] "VILLA QUINTEROS"                     
## [112] "YANIMA"                              
## [113] "YERBA BUENA"

creamos la Data de la jurisdicción (unidad) q nos interesa …

jurisdiccion <- fi_regions %>% 
  filter(juris == "MUN. DE FAMAILLA")

creamos la visualización con el objeto utilizando mapview

mapview(jurisdiccion, label = jurisdiccion$name, color = "darkgreen", col.regions = "green", alpha.regions = .05)

Traemos las capas que deseamos interceptar

baseurlrios <- "http://190.221.181.227/geoserver/dgct/wfs"
wfs_reqrios <- paste0("?", "request=GetFeature&service=WFS&version=2.0.0&typeName=dgct:rios&outputFormat=application/json")

fi_regions_wfs_rios <- paste0(baseurlrios, wfs_reqrios)

fi_regions_rios <- st_read(fi_regions_wfs_rios)
## Reading layer `OGRGeoJSON' from data source 
##   `http://190.221.181.227/geoserver/dgct/wfs?request=GetFeature&service=WFS&version=2.0.0&typeName=dgct:rios&outputFormat=application/json' 
##   using driver `GeoJSON'
## Simple feature collection with 204 features and 4 fields
## Geometry type: POLYGON
## Dimension:     XYZ
## Bounding box:  xmin: 3495318 ymin: 6901853 xmax: 3639369 ymax: 7118776
## z_range:       zmin: 0 zmax: 0
## Projected CRS: POSGAR 2007 / Argentina 3
mapview(fi_regions_rios, label = fi_regions_rios$name, color = "darkgreen", col.regions = "green", alpha.regions = .05)

Interceptamos con la unidad

### PRUEBA DE VISUALIZACIÓN CON BBOX desde la migración (NO FUNCIONÓ)

pero si para recortar el objeto con problemas: (cod)

** unificacion del sistema de coordenadas (CRS) ya quno está en wgs 84 y el otro en EPSG 5340, usamos el EPSG 5340 q es el posgar 2007 / 3 que es mas preciso. jurisdiccion_2 <- st_transform(jurisdiccion, st_crs(fi_regions_rios))

** Crear el bbox a partir de la capa jurisdicción bbox_jurisdiccion <- st_bbox(jurisdiccion_2)

** Filtrar los ríos que intersecan con el bbox rios_en_jurisdiccion <- st_intersection(fi_regions_rios, st_as_sfc(bbox_jurisdiccion))

** Visualizar ambas capas en el mismo mapa mapview(jurisdiccion) + mapview(rios_en_jurisdiccion, color = “blue”)


NOTA

como st_read sólo me permite leer los formatos, unificando los mismos, y map view visualizarlos. al parecer las capas no estan en condiciones de ser sometidas a geoprocesos. lo podemos ver al detectar el error (cuando queremos hacer la intersección)

“Error in UseMethod(”st_intersection”) : no applicable method for ‘st_intersection’ applied to an object of class “character””

y verificar usando class() que ambos son data.frame

por lo que debemos convertir el data.frame en un archivo sf.

#unificacion del sistema de coordenadas (CRS) ya  quno está en wgs 84 y el otro en EPSG 5340, usamos el EPSG 5340 q es el posgar 2007 / 3 que es mas preciso.
jurisdiccion_2 <- st_transform(jurisdiccion, st_crs(fi_regions_rios))
#convertimos los archivos de data frame (df) a sf (formato q contiene georeferencias) identificando la columna q contiene su geometría.
sf_obj_juris <- st_as_sf(jurisdiccion_2, geometry = "geometry")
sf_obj_rios <- st_as_sf(fi_regions_rios, geometry = "geometry")
parcelas_recortadas <- st_intersection(sf_obj_rios, sf_obj_juris)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
mapview(jurisdiccion_2, label = jurisdiccion$name, color = "darkgreen", col.regions = "green", alpha.regions = .05) +
mapview(parcelas_recortadas, label = parcelas_recortadas$name, color = "blue", col.regions = "blue", alpha.regions = .05)